/**
 * Created by WT-SUN on 2017/4/13.
 */
$(function () {
    $('#orgTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: true,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/occupationalHealth/hseServiceOrg/serviceOrgTable.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc'
        },
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'serviceName', title: '服务机构名称', width: 100},
            {field: 'serviceTypeName', title: '服务机构类型', width: 100},
            {field: 'aptitudeGrade', title: '资质等级', width: 100},
            {field: 'startTime', title: '开始日期', width: 100},
            {field: 'endTime', title: '结束日期', width: 100}
        ]]
    });
    queryComboData();
    $('#btn_clear').on("click", function () {
        $('#querySerForm').form('reset');
    });
    $('#btn_save').on("click", function () {
            var $selected = $('#orgTb').datagrid('getSelections');
            if($selected.length==0){
                layer.alert("请选择服务机构！");
                return;
            }
            WindowManager.closeLayer({
                returnValue: $selected
            });
    });
});

function queryComboData() {
    var code=CONSTANT.DictionaryTypeDefConstants.OHE_SERVICE_TYPE;
    $.ajax({
        type: 'post',
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',
        data: {code: code},
        dataType: "json",
        success: function (result) {
            $('#serviceTypeQuery').combobox({
                data: result,
                valueField: 'id',
                textField: 'text',
                editable: false,
                panelHeight: '200',
                onSelect: function (record) {
                }
            });
        }
    });
}
/**
 * 重新加载表格
 */
function reLoadData() {
    $('#orgTb').datagrid('clearSelections');
    var queryParams = $('#querySerForm').serializeJson();
    queryParams["sort"] = 'addTime';
    queryParams["order"] = 'desc';
    $('#orgTb').datagrid('options').queryParams = queryParams;
    $("#orgTb").datagrid('reload', ROOT_PATH + '/occupationalHealth/hseServiceOrg/serviceOrgTable.shtml');
}
